<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="./js/vue.min.js"></script>
    <title>计算属性的基本使用</title>
</head>
<body>
<div id="app">
    <!-- methods，即使firstName和lastName没有改变，也需要再次执行 -->
    <h2>{{getFullName()}}</h2>
    <h2>{{getFullName()}}</h2>
    <h2>{{getFullName()}}</h2>
    <h2>{{getFullName()}}</h2>
    <!-- 计算属性有缓存，只有关联属性改变才会再次计算 -->
    <h2>{{fullName}}</h2>
    <h2>{{fullName}}</h2>
    <h2>{{fullName}}</h2>
    <h2>{{fullName}}</h2>
</div>
</body>
<script>
    const app = new Vue({
        el:"#app",
        data:{
            firstName:"skt t1",
            lastName:"faker"
        },
        computed: {
            fullName(){
                console.log("调用了计算属性fullName");

                return this.firstName + " " + this.lastName
            }
        },
        methods: {
            getFullName(){
                console.log("调用了getFullName");

                return this.firstName + " " + this.lastName
            }
        },
    })
</script>
</html>